package hibernate;   

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class DAOLastSnapshot 
{
	private Session session = null;
	// Question 3
	public DTOLastSnapshotList getChangedCapacityStation()
	{
		DTOLastSnapshotList dtoLastSnapshotList = new DTOLastSnapshotList();
		try {
			SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
			session = sessionFactory.openSession();
			String q = "from LastSnapshot lastsnapshot where (lastsnapshot.available + lastsnapshot.free <> lastsnapshot.total)";
			System.out.println(q);
			Query query = session.createQuery(q);
			List<LastSnapshot> list = query.list();
			dtoLastSnapshotList.setLastSnapshotList(list);
			session.close();
		} catch (Exception e) {
			System.out.println(e.getMessage());
		} finally {
		}
		return dtoLastSnapshotList;
	}
	
	
	public static void main(String[] args) 
	{
		DAOLastSnapshot daoLastSnapshot = new DAOLastSnapshot();
		DTOLastSnapshotList dtoLastSnapshotList = daoLastSnapshot.getChangedCapacityStation();
		List<LastSnapshot> list = dtoLastSnapshotList.getLastSnapshotList(); 

		for (LastSnapshot l : list)
		{
				System.out.println(l);
		}
		System.out.println("Finish!");
	}
}
